package com.acxiom.bsh.util;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;

import com.acxiom.bsh.logger.LoggerManager;
import com.acxiom.bsh.pojo.LltPojo;


/**
 * 流量通需要的工具类
 * @author zhonganyuan
 *
 */
public class LltUtil {

	/**
	 * 流量充值url
	 */
	@Value("${llt.api.url.charge}")
	private String chargeUrl;

	/**
	 * 流量套餐url
	 */
	@Value("${llt.api.url.package}")
	private String packageUrl;
	
	/**
	 * 流量AppKey
	 */
	@Value("${llt.appKey}")
	private String appKey;
	
	/**
	 * 创建获取流量包接口签名
	 * @return
	 */
	//http://host.com/api.aspx?v=1.1&action=getPackage&account=帐号&sign=MD5
	public static String createGetPackageSign(String appKey){
		 StringBuffer sign = new StringBuffer();
		 sign.append("http://l.lmobile.cn/api.aspx");
		 sign.append("?account=lsgb01");
		 sign.append("&action=getPackage");
		 sign.append("&type=0");
		 sign.append("&v=1.1");
        return sign.toString()+"&sign="+Md5Util.getMD5Str("account=lsgb01&type=0&key="+appKey);
	}
	
	/**
	 * 单号码充流量
	 * @return
	 */
	public static String rechargeFlow(LltPojo lltPojo){
		 //拼装信息
		 StringBuffer url = new StringBuffer();
		 String sign = Md5Util.getMD5Str("account="+lltPojo.getAccount()+"&mobile="+lltPojo.getMobile()+"&package=100&key="+lltPojo.getAppKey());
		 url.append("http://l.lmobile.cn/api.aspx");
		 url.append("?account="+lltPojo.getAccount());
		 url.append("&action=charge");
		 url.append("&mobile="+lltPojo.getMobile());
		 url.append("&package=100");
		 url.append("&v=1.1");
		 url.append("&sign="+sign);
		 LoggerManager.getApiLogger().info("流量通流量开始充值==》"+url.toString());
		 String result = HttpUtil.sendGet(url.toString(),"");
		 
         return result;
	}
	
}
